"""
@Author  : 康帅
@Time    : 2021/3/26 10:02
@Function: 适配模式：插口转换
"""

from abc import ABCMeta, abstractmethod


class SocketEntity:
    """ 接口类型定义 """

    def __init__(self, socket_num, socket_type):
        self._socket_num = socket_num
        self._socket_type = socket_type

    def get_socket_num(self):
        return self._socket_num

    def set_socket_num(self, socket_num):
        self._socket_num = socket_num

    def get_socket_type(self):
        return self._socket_type

    def set_socket_type(self, socket_type):
        self._socket_type = socket_type


class ISocket(metaclass=ABCMeta):
    """ 插座基类 """

    @abstractmethod
    def get_name(self):
        pass

    @abstractmethod
    def get_socket(self):
        pass


class ChineseSocket(ISocket):
    """ 国标 """

    def get_name(self):
        return "国标插座"

    def get_socket(self):
        return SocketEntity(3, "八字扁形")


class BritishSocket(ISocket):
    """ 英标 """

    def get_name(self):
        return "英标插座"

    def get_socket(self):
        return SocketEntity(3, "T字方形")


class TransformSocket(ISocket):
    """ 插座转换器 """

    def __init__(self, british_socket):
        self._british_socket = british_socket

    def get_name(self):
        return self._british_socket.get_name() + "转换器"

    def get_socket(self):
        socket = self._british_socket.get_socket()
        socket.set_socket_type("八字扁形")
        return socket


def is_standard(name, socket):
    if socket.get_socket_num() == 3 and socket.get_socket_type() == "八字扁形":
        is_standard = "符合"
        is_charge = "可以"
    else:
        is_standard = "不符合"
        is_charge = "不可以"
    print(f"[{name}]:\n针脚数量：{socket.get_socket_num()}，针脚类型：{socket.get_socket_type()}，"
          f"{is_standard}中国的标准，{is_charge}给中国内地的电子设备充电")


if __name__ == '__main__':
    chinese_socket = ChineseSocket()
    is_standard(chinese_socket.get_name(), chinese_socket.get_socket())

    british_socket = BritishSocket()
    is_standard(british_socket.get_name(), british_socket.get_socket())

    transform_socket = TransformSocket(british_socket)
    is_standard(transform_socket.get_name(), transform_socket.get_socket())
